package testcases;
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;

import manager.Manager;

import ball.Ball;
import board.Board;
import junit.framework.TestCase;
public class TestBoard  extends TestCase{
	private Manager manager;
	private Map<Point,Ball> ballArray=new HashMap<Point, Ball>();
	private Ball ball;
	public void setUp() { 
		manager = new Manager(); 
		for(int i=0;i<6;i++){
			for(int j=0;j<6;j++){
				ballArray.put(new Point(i,j), null);
			}
		}
	}

	public void testgetLowestRow(){
		int result;
		Ball[] balls={new Ball(0,0,'4'),new Ball(1,0,'5'),new Ball(2,0,'5'),new Ball(0,1,'3'),new Ball(0,2,'4')};
		for(int i=0;i<balls.length;i++){
			this.ballArray.put(new Point(balls[i].getRow(),balls[i].getCol()),balls[i]);
		}
		
		int col = 0;
		manager.process(col);
		Board temBoard= manager.getBoard();
		temBoard.setBallArray(this.ballArray);
		result=temBoard.getLowestRow(col);
		assertEquals(result,3);
		}

	
	public void testisGameOver(){
		boolean result;
		Ball[] balls={new Ball(0,0,'o'),new Ball(1,0,'o'),new Ball(2,0,'o'),new Ball(3,0,'o'),new Ball(4,0,'o'),new Ball(5,0,'o')};
		for(int i=0;i<balls.length;i++){
			this.ballArray.put(new Point(balls[i].getRow(),balls[i].getCol()),balls[i]);
		}
		int col=0;
		manager.process(col);
		Board tempBoard=manager.getBoard();

		result=tempBoard.isGameOver();
		assertEquals(result,false);

	}
	public void testcheckBallCol(){
		boolean result;
		Ball[] balls={new Ball(0,0,'o'),new Ball(1,0,'o'),new Ball(2,0,'o'),new Ball(3,0,'o'),new Ball(4,0,'o'),new Ball(5,0,'o')};
		for(int i=0;i<balls.length;i++){
			this.ballArray.put(new Point(balls[i].getRow(),balls[i].getCol()),balls[i]);
		}
		int col=0;
		int row=0;
		manager.process(col);
		Board tempBoard=manager.getBoard();
		result=tempBoard.checkBallCol('4', col, col);
		assertEquals(result,false);
		
	}
	public void testcheckBallRow(){
		boolean result;
		Ball[] balls={new Ball(0,0,'o'),new Ball(1,0,'o'),new Ball(2,0,'o'),new Ball(3,0,'o')};
		for(int i=0;i<balls.length;i++){
			this.ballArray.put(new Point(balls[i].getRow(),balls[i].getCol()),balls[i]);
		}
		int col=0;
		int row=0;
		manager.process(row);
		Board tempBoard=manager.getBoard();
		result=tempBoard.checkBallRow('4', col, row);
		assertEquals(result,false);
	}
	
	public void testcheckBall(){
		boolean result;
		Ball[] balls={new Ball(0,0,'o'),new Ball(1,0,'o'),new Ball(2,0,'o'),new Ball(3,0,'o')};
		for(int i=0;i<balls.length;i++){
			this.ballArray.put(new Point(balls[i].getRow(),balls[i].getCol()),balls[i]);
		}
		int row=0;
		int col=0;
		manager.process(col);
		Board tempBoard=manager.getBoard();
		result=tempBoard.checkBall('5', col, row);
		assertEquals(result,false);
		
	}
	public void testcheckAllBalls(){
		boolean result;
		Ball[] balls={new Ball(0,0,'o'),new Ball(1,0,'o'),new Ball(2,0,'o'),new Ball(3,0,'o')};
		for(int i=0;i<balls.length;i++){
			this.ballArray.put(new Point(balls[i].getRow(),balls[i].getCol()),balls[i]);
		}
		int row=0;
		int col=0;
		manager.process(col);
		Board tempBoard=manager.getBoard();
		result=tempBoard.checkAllBalls();
		assertEquals(result,true);
	}
	
	public void testSetBall(){
		ball = new Ball(0,5,'4');
		Board temBoard = new Board();
		temBoard.setBall(ball);
		Ball result = temBoard.getBall();
		assertEquals(result,ball);
	}
	
	public void testSetBallArray(){
		Ball[] balls={new Ball(0,0,'o'),new Ball(1,0,'o'),new Ball(2,0,'o'),new Ball(3,0,'o')};
		Map<Point,Ball> ballArray=new HashMap<Point, Ball>();
		for(int i=0;i<balls.length;i++){
			ballArray.put(new Point(balls[i].getRow(),balls[i].getCol()),balls[i]);
		}
		Board temBoard = new Board();
		temBoard.setBallArray(ballArray);
		Map<Point,Ball> result = temBoard.getBallArray();
		assertEquals(result,ballArray);
	}
	

	
	
	
	
	
	
	
}
